# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=volk
pkgbase=mingw-w64-vulkan-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-vulkan-${_realname}")
pkgver=1.4.304
pkgrel=1
pkgdesc="Meta loader for Vulkan API (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/zeux/volk'
license=('spdx:MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-vulkan-headers"
  "${MINGW_PACKAGE_PREFIX}-vulkan-loader"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
)
source=("https://github.com/zeux/volk/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('ab3d4a8ccaeb32652259cdd008399504a41792675b0421d90b67729ee274746f')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DVOLK_INSTALL=ON \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE.md \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.md
}
